package com.ev.k3cloudBusiness.service.impl;

import com.ev.asl.constant.AslConstant;
import com.ev.framework.utils.R;
import com.ev.k3cloudBusiness.service.K3ExpectedStatusInTheLibraryService;
import com.ev.k3cloudBusiness.vo.ExpectedStatusInTheLibraryVo;
import com.ev.k3cloudBusiness.vo.K3DeeSyncVO;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 姚家乐
 * @since 2021/8/5 13:12
 */
@Slf4j
@Service
public class K3ExpectedStatusInTheLibraryServiceImpl implements K3ExpectedStatusInTheLibraryService {
    @Autowired
    private com.ev.k3cloud.service.kingdeeMiddlewareService kingdeeMiddlewareService;

    private K3DeeSyncVO<List<ExpectedStatusInTheLibraryVo>> syncVO(Map<String,String> param){
        String expectedStatusInTheLibraryAll = kingdeeMiddlewareService.expectedStatusInTheLibraryAll(param);
        return new Gson().fromJson(expectedStatusInTheLibraryAll,
                new TypeToken<K3DeeSyncVO<List<ExpectedStatusInTheLibraryVo>>>() {
                }.getType());
    }

    @Override
    public R expectedStatusInTheLibrarySync(Map<String, String> param) {
        K3DeeSyncVO<List<ExpectedStatusInTheLibraryVo>> k3DeeSyncVO = this.syncVO(param);
        if (!AslConstant.ZERO.equals(k3DeeSyncVO.getCode())) {
            log.info(k3DeeSyncVO.getMsg());
            return R.error(k3DeeSyncVO.getMsg());
        }
        Map<String,Object> data = Maps.newHashMap();
        List<ExpectedStatusInTheLibraryVo> mrDdVo = k3DeeSyncVO.getData();
        data.put("data",mrDdVo);
        if (String.valueOf(param.get("flag")).equals("1")){
            data.put("pageNo",k3DeeSyncVO.getPageNo());
            data.put("pageSize",k3DeeSyncVO.getPageSize());
            data.put("total",k3DeeSyncVO.getTotal());
            data.put("totalPage",k3DeeSyncVO.getTotalPage());
        }
        return R.ok(data);
    }
}
